(function($){

    var goToTopTime;
    $.fn.goToTop=function(options){
        var opts = $.extend({},$.fn.goToTop.def,options);
        var $window=$(window);
        $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body'); // opera fix
        //$(this).hide();
        var $this=$(this);
        clearTimeout(goToTopTime);
        goToTopTime=setTimeout(function(){
            /*var controlLeft;
            if ($window.width() > opts.pageHeightJg * 2 + opts.pageWidth) {
                controlLeft = ($window.width() - opts.pageWidth) / 2 + opts.pageWidth + opts.pageWidthJg;
            }else{
                controlLeft = $window.width()- opts.pageWidthJg-$this.width();
            }
            //alert('ok');
            //var cssfixedsupport=($.browser.msie && parseFloat($.browser.version) < 7);//判断是否ie6
            //var cssfixedsupport=($.browser.msie && ($.browser.version == "6.0") && !$.support.style);

            var cssfixedsupport=false;
            var controlTop=$window.height() - $this.height()-opts.pageHeightJg;
            alert($window.height());
            alert($this.height());
            alert(opts.pageHeightJg);
            controlTop=cssfixedsupport ? $window.scrollTop() + controlTop : controlTop;
            */
            //alert('ok');
            var shouldvisible=( $window.scrollTop() >= opts.startline )? true : false;

            //alert(controlTop);

            if (shouldvisible){
                $this.stop().show();
            }else{
                $this.stop().hide();
            }
            //alert(shouldvisible);
            $this.css({
                //position: cssfixedsupport ? 'absolute' : 'fixed',
                position: 'fixed',
                top: '750px',
                left: '1455px',
            });
        },30);

        $(this).click(function(event){
            $body.stop().animate( { scrollTop: $(opts.targetObg).offset().top}, opts.duration);
            $(this).blur();
            event.preventDefault();
            event.stopPropagation();
        });
    };

    $.fn.goToTop.def={
        pageWidth:910,//页面宽度
        pageWidthJg:2,//按钮和页面的间隔距离
        pageHeightJg:100,//按钮和页面底部的间隔距离
        startline:30,//出现回到顶部按钮的滚动条scrollTop距离
        duration:200,//回到顶部的速度时间
        targetObg:"body"//目标位置
    };
})(jQuery);
$(function(){
    $('<a href="javascript:;" class="backToTop" title="返回顶部">返回顶部</a>').appendTo("body");
});